var _v;
var vueModel = {
    el: '#container',
    data: {
        params: {
            page: 1,
            limit: 15,
            order_by: '',
            sort: '',
            dis_self_sn: '',
            dist_order_sn: '',
            in_date_start: '',
            in_date_end: '',
            hotel_name: '',
            hotel_order_sn: '',
            contract_member: '',
            contract_mobile: '',
            pay_type: '',
            created_at_start: '',
            created_at_end: '',
            status: '',
        },
        inDate: [],
        buyDate: [],
        orderList: [],
        dialogVisible: false,
        cancelText: '',
        currOrderId: ''
    },
    computed: {
        roomType: function() {
            return function (room_type_id) {
                switch (parseInt(room_type_id)) {
                    case 1:
                        return '标准房'
                        break;
                    case 2:
                        return '高级房'
                        break;
                    case 3:
                        return '豪华房'
                        break;
                    case 4:
                        return '商务房'
                        break;
                    case 5:
                        return '行政房'
                        break;
                    case 6:
                        return '双人房'
                        break;
                    case 7:
                        return '单人房'
                        break;
                    case 8:
                        return '豪华套房'
                        break;
                }

            }
        }
    },
    methods: {
/*/room/order/submit     提交
/room/order/confirm_payed_pre  确认已预付
/room/order/cancel   取消
/room/order/apply_cancel  申请取消*/
        confirmSubmit: function(item) {
            this.$confirm('确认提交订单?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                HQ.ajax('/room/order/submit', JSON.stringify({ hotel_order_id: item.hotel_order_id }), function(res){
                    _v.$message({
                        type: 'success',
                        message: '操作成功!'
                    });
                    _v.fetchData();
                }, function(){}, "POST");
            }).catch(() => {});
        },
        cancelOrder: function(item) {
            this.$confirm('确认取消订单?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                HQ.ajax('/room/order/cancel', JSON.stringify({ hotel_order_id: item.hotel_order_id }), function(res){
                    _v.$message({
                        type: 'success',
                        message: '操作成功!'
                    });
                    _v.fetchData();
                }, function(){}, "POST");
            }).catch(() => {});
        },
        confirmPayPre: function(item) {
            this.$confirm('确认预付?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                HQ.ajax('/room/order/confirm_payed_pre', JSON.stringify({ hotel_order_id: item.hotel_order_id }), function(res){
                    _v.$message({
                        type: 'success',
                        message: '操作成功!'
                    });
                    _v.fetchData();
                }, function(){}, "POST");
            }).catch(() => {});
        },
        applyCancel: function() {
            HQ.ajax('/room/order/apply_cancel', JSON.stringify({ hotel_order_id: _v.currOrderId, reason: _v.cancelText }), function(res) {
                _v.$message({
                    type: 'success',
                    message: '操作成功!'
                });
                _v.dialogVisible = false;
                _v.fetchData();
            })
        },
        changeBuyDate: function(date) {
            if (date.length > 0) {
                _v.params.created_at_start = moment(date[0]).format('YYYY-MM-DD');
                _v.params.created_at_end = moment(date[1]).format('YYYY-MM-DD');
            } else {
                _v.params.created_at_start = '';
                _v.params.created_at_end = '';
            }
            _v.fetchData();
        },
        changeInDate: function(date) {
            if (date.length > 0) {
                _v.params.in_date_start = moment(date[0]).format('YYYY-MM-DD');
                _v.params.in_date_end = moment(date[1]).format('YYYY-MM-DD');
            } else {
                _v.params.in_date_start = '';
                _v.params.in_date_end = '';
            }
            _v.fetchData();
        },
        getQueryVariable: function (variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        },
        fetchData: function () {
            HQ.ajax('/room/order/list', JSON.stringify(_v.params), function(res){
                _v.orderList = res.data.list;
                console.log(_v.orderList)
            }, function(){}, "POST");
        },
    },
    created: function() {
        _v = this;
    },
    mounted: function () {
        _v.fetchData();
    }
}

$(function() {
    new Vue(vueModel);
})